package com.wyw.function.learning.demo3;

import com.wyw.function.learning.common.Apple;
import com.wyw.function.learning.common.AppleClient;
import com.wyw.function.learning.common.AppleComparator;

import java.util.Comparator;
import java.util.List;

/**
 * @Title   方法引用demo
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * Update History:
 * Author        Time            Content
 */
public class DemoClient7 {

    // 1、简单的实现
//    public static void main(String[] args) {
//        List<Apple> apples = AppleClient.getApples();
//        apples.sort(new AppleComparator());
//    }

    // 2、使用匿名内部类
//    public static void main(String[] args) {
//        List<Apple> apples = AppleClient.getApples();
//        apples.sort(new Comparator<Apple>() {
//            @Override
//            public int compare(Apple o1, Apple o2) {
//                return o1.getWeight() - o2.getWeight();
//            }
//        });
//    }

//    // 3、使用Lambda表达式
//    public static void main(String[] args) {
//        List<Apple> apples = AppleClient.getApples();
//        apples.sort(((o1, o2) -> o1.getWeight() - o2.getWeight()));
//    }

//    // 4、简化Lambda表达式
//    public static void main(String[] args) {
//        List<Apple> apples = AppleClient.getApples();
//        Comparator<Apple> comparing = Comparator.comparing((Apple a) -> a.getWeight());
//        apples.sort(comparing);
//    }

    // 5、在4基础上简化
//    public static void main(String[] args) {
//        List<Apple> apples = AppleClient.getApples();
//        apples.sort(Comparator.comparing((Apple a) -> a.getWeight()));
//    }

    // 6、使用方法引用
    public static void main(String[] args) {
        List<Apple> apples = AppleClient.getApples();
        apples.sort(Comparator.comparing(Apple::getWeight));
    }
}
